﻿using IDAL;

namespace DAL
{
    public class BaseDAl<T> : IBaseDAL<T> where T : class
    {
        public BaseDAl(HotelDbContext Db)
        {
            this.Db = Db;
        }

        public HotelDbContext Db { get; }

        public Task<int> AddAsync(T t)
        {
            Db.Set<T>().Add(t);
            return Db.SaveChangesAsync();
        }

        public Task<int> AddAsyncList(List<T> t)
        {
            Db.Set<T>().AddRange(t);
            return Db.SaveChangesAsync();
        }

        public Task<int> DeleteAsync(T t)
        {
            Db.Set<T>().Remove(t);
            return Db.SaveChangesAsync();
        }

        public Task<int> DeleteAsyncList(List<T> t)
        {
            Db.Set<T>().RemoveRange(t);
            return Db.SaveChangesAsync();
        }

        public IQueryable<T> GetAll()
        {
            return Db.Set<T>();
        }
        public Task<int> UpdateAsync(T t)
        {
            Db.Set<T>().Update(t);
            return Db.SaveChangesAsync();
        }

        public Task<int> UpdateAsyncList(List<T> t)
        {
            Db.Set<T>().UpdateRange(t);
            return Db.SaveChangesAsync();
        }
    }
}
